package com.fwh.gmall.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

@Configuration
public class StarRocksConfig {

    /**
     * StarRocks数据源
     */
    @Bean(name = "getStarRocksDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.starrocks")
    public DataSource getStarRocksDataSource() {
        return DataSourceBuilder.create().build();
    }

    /**
     * StarRocks JdbcTemplate
     */
    @Bean(name = "getStarRocksJdbcTemplate")
    public JdbcTemplate getStarRocksJdbcTemplate(@Qualifier("getStarRocksDataSource") DataSource dataSource) {
        return new JdbcTemplate(getStarRocksDataSource());
    }



}
